<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.yaodian100.core.common.utils.ServerValue"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ include file="/taglibs.jsp"%>
<c-rt:set var="midContextPath" value='<%=ServerValue.getMidContextPath()%>'/>
<script language="javascript">
	$().ready( function() {
		$("input[name='optionCode']").each(function(i,item){
			if(item.value !=''){
				$(this).attr("readonly", true);
			}
		});

		$("#newOpn").click(function() {
			var sOpt="<tr class=''>"+
    		"<td><input type='hidden' size='10' name='optionId' id='optionId' value='' /></td>"+
			"<td><input type='text' size='10' name='optionCode' id='optionCode' value=''/></td>"+
			"<td><input type='text' name='optionName' id='optionName' value='' /></td>"+
			"<td><select id='optionMemoOne' name='optionMemoOne'>" +
			"<option value='0'>站外</option><option value='1'>站内</option>" +
			"</select></td>" +
			"<td></td>" +
			"</tr>";
			$("#addOption").append(sOpt);
		});
		
		$("#submit_button").click(function(){
			try {
				$("input[id*='optionCode_']").each(function(i,item){
					if( "" == $(this).val() ){
						alert("渠道代码为必填");
						$(this).focus();
						throw item;
					}
				});
			}catch(e){
				return false;
			}
			try {
				$("input[id*='optionCode_']").each(function(i,item){
					if ( "" != $(this).val() ){
						if ( this.value.match(/(.[^a-zA-Z0-9])/ig) ){
							alert("渠道代码只能输入英数字");
							$(this).focus();
							throw item;
						}
					}
				});
			}catch(e){
				return false;
			}
			try {
				$("input[id*='optionName_']").each(function(i,item){
					if( $(this).val() == ""){
						alert("渠道名称为必填");
						$(this).focus();
						throw item;
					}
				});
			}catch(e){
				return false;
			}		
			try {
				if ( "" != $("#optionCode").val() || "" != $("#optionName").val()){
					if( "" == $("#optionCode").val() ){
						alert("渠道代码为必填1");
						$("#optionCode").focus();
						throw $("#optionCode").val();
					}
					if ( $("#optionCode").val().match(/(.[^a-zA-Z0-9])/ig) ){
						alert("渠道代码只能输入英数字");
						$("#optionCode").focus();
						throw $("#optionCode").val();
					}
					if( "" == $("#optionName").val() ){
						alert("渠道名称为必填");
						$("#optionName").focus();
						throw $("#optionName").val();
					}
				}   
			}catch(e){
				return false;
			}			
			$("#menuForm").submit();
		});
});
</script>	
<h1>渠道选单维护管理<br/>
<div class="f-link">
	<c-rt:choose>
		<c-rt:when test="${editType eq 'bonus'}">
			<a href="${midContextPath}/memberevent/search.do">回注册送积分或礼卷列表</a>
		</c-rt:when>
		<c-rt:when test="${editType eq 'channel'}">
			<a href="${midContextPath}/channel/search.do">回渠道广告管理列表</a>
		</c-rt:when>
	</c-rt:choose>
	<a href="http://10.0.1.1/jinwei/menuInit.html" target="_blank">更新menu(更新后请重新登入)</a>
</div>
</h1>
<s:actionerror />
<s:actionmessage />
<s:fielderror />
<br/>
<s:form action="saveChannel.do" method="post" id="menuForm">
<table class="tb-data" width="100%">	
	 <thead>                   
	   <tr>
	       <th>#</th>
	       <th>渠道代码</th>
	       <th>渠道名称</th>
	       <th>渠道来源</th>
	       <th></th>
	   </tr>
		</thead>
	  <tbody>
			<c-rt:forEach items="${optionCodes}" var="option" varStatus="rows_index">        
				<tr class="${rows_index.count % 2 == 0 ? 'bg-yl' : ''}">	
					<td><input type="hidden" size="10" name="optionId" id="optionId_${rows_index.count}" value="${option.oid}" />${option.oid}</td>
					<td><input type="text" size="30" name="optionCode" id="optionCode_${rows_index.count}" value="${option.code}"/></td>
					<td><input type="text" size="30" name="optionName" id="optionName_${rows_index.count}" value="${option.name}" /></td>
					<td><select id="optionMemoOne_${rows_index.count}" name="optionMemoOne">
						<option value="0"  ${option.memo1 eq "0" ? "selected" : ""}>站外</option>
						<option value="1" ${option.memo1 eq "1" ? "selected" : ""}>站内</option>
					</select></td>
					<td></td>
				</tr>
			</c-rt:forEach>    
			<tr class="">
	    		<td><input type="hidden" size="10" name="optionId" id="optionId" value="" /></td>
					<td><input type="text" size="30" name="optionCode" id="optionCode" value="" maxlength="30"/><br/>
					<span class="txt-rd">【※长度限制30个字】</span>
					</td>
					<td><input type="text" size="30" name="optionName" id="optionName" value="" maxlength="60"/></td>
					<td><select id="optionMemoOne" name="optionMemoOne">
						<option value="0">站外</option>
						<option value="1">站内</option>
					</select></td>
					<td><a href="javascript:;" id="newOpn">添加新的Option</a></td>
	    	</tr> 
	  </tbody>		
	  <tbody id="addOption"></tbody>
		<tr class="">
			<td colspan="4">
				<input type="button" id="submit_button" value="储存"/>
			</td>
		</tr>
	</table>
</s:form>